import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'product_value.dart';
class Product extends StatefulWidget {
  final Map<String,dynamic> product;
  final List<dynamic> productValue;
  final key;
  Product({this.key,this.product,this.productValue});

  _ProductState createState() => _ProductState();
}

class _ProductState extends State<Product>
    with AutomaticKeepAliveClientMixin {
  Map<String,dynamic> product;//产品详情
  List<dynamic> productValue;//产品属性
  bool get wantKeepAlive => true;
  var actionEventBus;

  @override
  void initState() {
    super.initState();
    this.product = widget.product;
    this.productValue = widget.productValue;
  }


  //底部弹出框
  _attrBottomSheet() {
    print(productValue);
    showModalBottomSheet(
      enableDrag: false,
        isScrollControlled:true,
        shape:RoundedRectangleBorder(
            borderRadius:BorderRadius.only(
              topLeft: Radius.circular(20),
              topRight: Radius.circular(20),
            )
        ),
        context: context,
        builder: (context) {
          return Container(
            height:900.w,
            child:ProductValue(product:product,productValue:productValue) ,
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Container(
      decoration: BoxDecoration(
        color: Colors.white
      ),
      child: Column(
        children: <Widget>[

          //标题
          Container(
            alignment: Alignment.centerLeft,
            padding:EdgeInsets.all(10.w),
            child: Text("${product['productName']}",
                textAlign: TextAlign.left,
                style: TextStyle(
                    color: Colors.black87, fontSize: 36.sp)),
          ),
          //价格
          Container(
            padding:EdgeInsets.all(10.w),
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Row(
                    children: <Widget>[
                      Text("原价: "),
                      Text("¥${product['otPrice']}",
                          style: TextStyle(
                              color: Colors.black38,
                              fontSize: 28.sp,
                              decoration: TextDecoration.lineThrough)),
                    ],
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Row(
                    children: <Widget>[
                      Text("库存: "),
                      Text("${product['stock']}${product['unitName']}",
                          style: TextStyle(
                            color: Colors.black38,
                            fontSize: 28.sp,
                          )),
                    ],
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Row(
                    children: <Widget>[
                      Text("特价: "),
                      Text("¥${product['price']}",
                          style: TextStyle(
                              color: Colors.red,
                              fontSize: 46.sp)),
                    ],
                  ),
                ),

              ],
            ),
          ),
          //筛选
          this.productValue.length > 0
              ? Container(
            margin: EdgeInsets.only(top: 10),
            height: 80.h,
            child: InkWell(
              onTap: () {
                _attrBottomSheet();
              },
              child: Row(
                children: <Widget>[
                  Text("已选择: ",
                      style: TextStyle(fontWeight: FontWeight.bold)),
                  Text("${productValue[0]['suk']}")
                ],
              ),
            ),
          )
              : Text(""),
          Divider(),
          Container(
            height: 100.h,
            child: Row(
              children: <Widget>[
                Text("运费: ", style: TextStyle(fontWeight: FontWeight.bold)),
                Text("￥${product['postage']}元")
              ],
            ),
          ),
        ],
      ),
    );
  }
}
